<?php
include_once ("db_mysql.php");

function getAllFriends($fild="name",$Order, $name = "", $table="friends"){
	
    $order[$fild]=$Order;
	
	$sql = "SELECT * FROM ".$table;
	
	if ($name <> "") {
		if ($name == "nopic") {
			$sql.=" WHERE pic = 'http://x.myspacecdn.com/modules/common/static/img/no_pic.gif'";
		}else{
			if ($table == "friends") {
				$sql.=" WHERE name LIKE '".$name."'";
			}else{
				$sql.=" WHERE (name LIKE '".$name."' OR owner = '".$name."') AND del LIKE '-1'";
			}
		}
	}
	
	if (is_array($order)){
		$i=0;
		foreach ($order as $column=>$orderType) {
			$i++;
			$sql.=" ORDER BY $column $orderType";
			if ($i<count($order)) $sql.=", ";
		}			
	}
	//echo $sql;
	return dbquery($sql);
}

	/**
	* Counts records in given query
	* @param String $query_string
	* @return int Number of records contained in query
	*/
	function numRows($query){
		$count=mysql_num_rows($query);
		return $count;		
	}

	function fuck($tab = 'pool'){
		$sql = "DELETE FROM ".$tab." WHERE id in (SELECT id FROM friends)";
		dbquery($sql);
		$sql = "DELETE FROM ".$tab." WHERE pic = 'http://x.myspacecdn.com/modules/common/static/img/deleteduser.gif'";
		dbquery($sql);
		$sql = "DELETE FROM `pool` WHERE del =0 AND adddate < DATE_SUB( NOW( ) , INTERVAL 7 DAY )";
		dbquery($sql);
		$sql = " OPTIMIZE TABLE `pool`";
		dbquery($sql);
		$sql = " OPTIMIZE TABLE `friends`";
		dbquery($sql);
	}
	
	function deleteMiser($id){
		$sql = "DELETE FROM 'pool' WHERE id = '".$id."'";
	}
	
	function showOwner(){
		$sql = "SELECT pool.owner FROM pool WHERE pool.owner IS NOT NULL GROUP BY owner ORDER BY id DESC";
		return dbquery($sql);	
	}		/**	 * Friends hour statistik	 */	function getFriendsHourStatistik(){		$sql = "select count(id) AS Anzahl,date_format(`friends`.`AddDate`,_utf8'%d.%m.%Y %H') AS `Datum` from `friends` group by date_format(`friends`.`AddDate`,_utf8'%d.%m.%Y %H') order by `friends`.`AddDate` desc LIMIT 0 , 60";		return dbquery($sql);				}
?>